#ifndef _C_SEQUENCER_H_
#define _C_SEQUENCER_H_

#include "types/types.h"
#include "types/TStaticQueue.h"
#include "CPath.h"
#include "CImage.h"
#include "timers.h"
#include <vector>

using namespace std;

class CView;
class CRenderer;

#define MAX_SHUFFLE_LENGTH				20
#define DEFAULT_NB_RESERVED_FILE_INFOS	100
#define MAX_SHUFFLE_ITERATION_COUNT		20

//----------------------------------------------
class CFileInfo
{
public:
	CFileInfo() {}
	CFileInfo(const xchar* sPath) : m_oPath(sPath) {}
	CFileInfo(const CFileInfo& oInfo) : m_oPath(oInfo.m_oPath) {}

	//bool isAvailable	() const { return m_eFileStatus == E_STATUS_NONE; }

	CPath			m_oPath;
	EImageType		m_eImageType;
	CImage			m_oImage;
};

//----------------------------------------------
class SSequencer
{
	DECLARE_SINGLETON(SSequencer);

public:
	SSequencer();
	~SSequencer();

	void		clearFileList		();
	void		loadFileList		();
	void		update				();
	bool		loadNextFile		();
	void		changeCurrentImage	();
	void		run					();
	void		onFileListReady		();
	void		onImageShowTimer	();

private:
	class CTimerImageShow : public CTimer
	{
	public:
		CTimerImageShow() : CTimer(1.f, true), m_sequencer(NULL) {}

		virtual void	onTimer			();
		void			setSequencer	(SSequencer* pSequencer) { m_sequencer = pSequencer; }
	private:
		SSequencer* m_sequencer;
	};

	void		loadFileListFromDir		(const xstring& sDir);
	bool		imageAlreadyInHistory	(const CFileInfo& oFileInfo) const;

	typedef TStaticQueue<uint32, MAX_SHUFFLE_LENGTH> THistory;

	THistory				m_oPathHashHistory;
	vector<CFileInfo*>		m_oFiles;
	CImagePool				m_oImagePool;
	CTimerImageShow			m_oImageShowTimer;
};

#endif
